package com.qf.contract.controller;

import com.qf.common.base.exception.ControllerException;
import com.qf.common.base.exception.ServiceException;
import com.qf.common.base.result.RespResult;
import com.qf.common.base.result.ResultCode;
import com.qf.contract.entity.FTypeOfContract;
import com.qf.contract.service.FTypeOfContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 合同类型的增删改查
 */
@Api(tags = "合同类型的增删改查")
@RestController
@RequestMapping("/ftypeofcontractcontroller")
public class FTypeOfContractController {
    @Resource
    FTypeOfContractService fTypeOfContractService;

    @ApiOperation("合同类型增加")
    @PutMapping("/addftypeofcontract")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult addFTypeOfContract(FTypeOfContract fTypeOfContract) {
        try {
            return RespResult.success(fTypeOfContractService.addFTypeOfContract(fTypeOfContract));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    @ApiOperation("合同类型删除")
    @DeleteMapping("/delftypeofcontract")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult delFTypeOfContract(int id) {
        try {
            return RespResult.success(fTypeOfContractService.delFTypeOfContract(id));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    @ApiOperation("合同类型修改")
    @PutMapping("/upftypeofcontract")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult upFTypeOfContract(FTypeOfContract fTypeOfContract) {
        try {
            return RespResult.success(fTypeOfContractService.upFTypeOfContract(fTypeOfContract));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    @ApiOperation("合同类型查询")
    @GetMapping("/selectftypeofcontract")
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult selectFTypeOfContract(@RequestParam(defaultValue = "1") int current, @RequestParam(defaultValue = "10")int size) {
        try {
            return RespResult.success(fTypeOfContractService.selectFTypeOfContract(current, size));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

}
